package com.wangwen.wechatmp.utils;

import java.security.MessageDigest;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.function.Supplier;

/**
 * @Author: wangwei
 * @Date: 2019/11/26 19:15
 */

public class SecuritySHA1Utils {

    /**
     * @Comment SHA1实现
     * @Author Ron
     * @Date 2017年9月13日 下午3:30:36
     * @return
     */
    public static String shaEncode(String inStr) throws Exception {
        MessageDigest sha = null;
        try {
            sha = MessageDigest.getInstance("SHA");
        } catch (Exception e) {
            System.out.println(e.toString());
            e.printStackTrace();
            return "";
        }

        byte[] byteArray = inStr.getBytes("UTF-8");
        byte[] md5Bytes = sha.digest(byteArray);
        StringBuffer hexValue = new StringBuffer();
        for (int i = 0; i < md5Bytes.length; i++) {
            int val = ((int) md5Bytes[i]) & 0xff;
            if (val < 16) {
                hexValue.append("0");
            }
            hexValue.append(Integer.toHexString(val));
        }
        return hexValue.toString();
    }

    public static void main(String args[]) throws Exception {
//        String str = new String("amigoxiexiexingxing");
//        System.out.println("原始：" + str);
//        System.out.println("SHA后：" + shaEncode(str));
//        System.out.println(((int)Math.ceil((double)21/(double)10)));
//        System.out.println(((int)Math.floor((double)21/(double)10)));
//        System.out.println("main函数开始执行");
//        ExecutorService executor = Executors.newFixedThreadPool(2);
//        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(new Supplier<Integer>() {
//            @Override
//            public Integer get() {
//                System.out.println("===task start===");
//                try {
//                    Thread.sleep(5000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                System.out.println("===task finish===");
//                return 3;
//            }
//        }, executor);
//        future.thenAccept(e -> System.out.println(e));
//        System.out.println("main函数执行结束");

        System.out.println("main函数开始执行");
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("===task start===");
                try {
                    Thread.sleep(8000);
                    System.out.println("===task finish===");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        thread.start();
        System.out.println("main函数执行结束");

    }
}

